
template<class T>
void readInMasiero11(T myAst[], long indLastMPC, long indLastNumbMPC, string* ids, long nIds)
{
  string line;
  ifstream myfile ("Masiero2011_apj398969t1_mrt.txt");
  long ind;
  AsteroidWithPole ast;

  if (myfile.is_open())
  {
    for (int j=0; j<49; j++)  // Masiero File Header
      getline (myfile,line) ; // skip header

    while ( getline (myfile,line))
      if (line.length()>1)
	{
	  // convert linefile to asteroid
	  ast.reset();
	  ast.Masiero11String2Asteroid(line);
	  if ((ind=ast.match(myAst,indLastMPC,indLastNumbMPC+1, ids, nIds))>=0) {
	      myAst[ind].D=ast.D;
	      myAst[ind].sigmaD=ast.sigmaD;
	      myAst[ind].pV=ast.pV;
	      myAst[ind].sigmapV=ast.sigmapV;
	      myAst[ind].eta=ast.eta;
	      myAst[ind].sigmaEta=ast.sigmaEta;
	      myAst[ind].pIR=ast.pIR;
	      myAst[ind].sigmapIR=ast.sigmapIR;
	      myAst[ind].nW1=ast.nW1;
	      myAst[ind].nW2=ast.nW1;
	      myAst[ind].nW3=ast.nW3;
	      myAst[ind].nW4=ast.nW4;
	      myAst[ind].refs[3]+=MASIERO11;
	  }
	  else {
	    cout << ">>match FAILED  " << ast.Designation << " -- " << line << endl;
	  }
	}
    myfile.close();
  }
  else cout << "Unable to open file"; 
}

template<class T>
void readInMasiero12(T myAst[], long indLastMPC, long indLastNumbMPC, string* ids, long nIds)
{
  string line;
  ifstream myfile ("Masiero2012_apjl447085t1_mrt.txt");
  long ind;
  AsteroidWithPole ast;

  if (myfile.is_open())
  {
    for (int j=0; j<24; j++)  // Masiero File Header
      getline (myfile,line) ; // skip header

    while ( getline (myfile,line))
      if (line.length()>1)
	{
	  // convert linefile to asteroid
	  ast.reset();
	  ast.Masiero12String2Asteroid(line);
	  if ((ind=ast.match(myAst,indLastMPC,indLastNumbMPC+1, ids, nIds))>=0) {
	      myAst[ast.Number-1].D=ast.D;
	      myAst[ast.Number-1].sigmaD=ast.sigmaD;
	      myAst[ast.Number-1].pV=ast.pV;
	      myAst[ast.Number-1].sigmapV=ast.sigmapV;
	      myAst[ast.Number-1].pIR=ast.pIR;
	      myAst[ast.Number-1].sigmapIR=ast.sigmapIR;
	      myAst[ast.Number-1].nW1=ast.nW1;
	      myAst[ast.Number-1].nW2=ast.nW1;
	      myAst[ast.Number-1].nW3=ast.nW3;
	      myAst[ast.Number-1].nW4=ast.nW4;
	      myAst[ast.Number-1].refs[3]+=MASIERO12;
	  }
	  else {
	    cout << ">>match FAILED  " << ast.Designation << " -- " << line << endl;
	  }
	}
    myfile.close();
  }
  else cout << "Unable to open file"; 
}

template<class T>
void readInMasiero14(T myAst[], long indLastMPC, long indLastNumbMPC, string* ids, long nIds)
{
  string line;
  ifstream myfile ("Masiero2014apj498786t1_mrt.txt");
  long ind;
  AsteroidWithPole ast;

  if (myfile.is_open())
  {
    for (int j=0; j<27; j++)  // Masiero File Header
      getline (myfile,line) ; // skip header

    while ( getline (myfile,line))
      if (line.length()>1)
	{
	  // convert linefile to asteroid
	  ast.Masiero14String2Asteroid(line);
      	  // if the asteroid is Numbered in the file assing it
	  if (ast.Number>0)
	    {
	      myAst[ast.Number-1].D=ast.D;
	      myAst[ast.Number-1].sigmaD=ast.sigmaD;
	      myAst[ast.Number-1].pV=ast.pV;
	      myAst[ast.Number-1].sigmapV=ast.sigmapV;
	      myAst[ast.Number-1].eta=ast.eta;
	      myAst[ast.Number-1].sigmaEta=ast.sigmaEta;
	      myAst[ast.Number-1].pIR=ast.pIR;
	      myAst[ast.Number-1].sigmapIR=ast.sigmapIR;
	      myAst[ast.Number-1].nW1=ast.nW1;
	      myAst[ast.Number-1].nW2=ast.nW1;
	      myAst[ast.Number-1].nW3=ast.nW3;
	      myAst[ast.Number-1].nW4=ast.nW4;
	      myAst[ast.Number-1].refs[3]+=MASIERO14;
	    }
	  else
	    {
	      // can you match is right there ?
	      if ((ind = findUnnumberedAst(myAst,ast,indLastMPC,indLastNumbMPC+1))>=0) // YES ! 
		{
		  myAst[ind].D=ast.D;
		  myAst[ind].sigmaD=ast.sigmaD;
		  myAst[ind].pV=ast.pV;
		  myAst[ind].sigmapV=ast.sigmapV;
		  myAst[ind].eta=ast.eta;
		  myAst[ind].sigmaEta=ast.sigmaEta;
		  myAst[ind].pIR=ast.pIR;
		  myAst[ind].sigmapIR=ast.sigmapIR;
		  myAst[ind].nW1=ast.nW1;
		  myAst[ind].nW2=ast.nW1;
		  myAst[ind].nW3=ast.nW3;
		  myAst[ind].nW4=ast.nW4;
		  myAst[ind].refs[3]+=MASIERO14;
		  //		  cout << ">>match 1  " << ast.pack << endl;
		}
	      else
		{ // the designation could not be matched.
		  // try to see if the asteroid has been numbered LATER
		  ast.findId(ids,nIds);
		  if (ast.Number>0)
		    {
		      myAst[ast.Number-1].D=ast.D;
		      myAst[ast.Number-1].sigmaD=ast.sigmaD;
		      myAst[ast.Number-1].pV=ast.pV;
		      myAst[ast.Number-1].sigmapV=ast.sigmapV;
		      myAst[ast.Number-1].eta=ast.eta;
		      myAst[ast.Number-1].sigmaEta=ast.sigmaEta;
		      myAst[ast.Number-1].pIR=ast.pIR;
		      myAst[ast.Number-1].sigmapIR=ast.sigmapIR;
		      myAst[ast.Number-1].nW1=ast.nW1;
		      myAst[ast.Number-1].nW2=ast.nW1;
		      myAst[ast.Number-1].nW3=ast.nW3;
		      myAst[ast.Number-1].nW4=ast.nW4;
		      myAst[ast.Number-1].refs[3]+=MASIERO14;
		      //		      cout << ">>match 2  " << ast.pack << endl;
		    }
		  else
		    {
		      if ((ind = findUnnumberedAst(myAst,ast,indLastMPC,indLastNumbMPC+1))>=0) // YES ! 
			{
			  myAst[ind].D=ast.D;
			  myAst[ind].sigmaD=ast.sigmaD;
			  myAst[ind].pV=ast.pV;
			  myAst[ind].sigmapV=ast.sigmapV;
			  myAst[ind].eta=ast.eta;
			  myAst[ind].sigmaEta=ast.sigmaEta;
			  myAst[ind].pIR=ast.pIR;
			  myAst[ind].sigmapIR=ast.sigmapIR;
			  myAst[ind].nW1=ast.nW1;
			  myAst[ind].nW2=ast.nW1;
			  myAst[ind].nW3=ast.nW3;
			  myAst[ind].nW4=ast.nW4;
			  myAst[ind].refs[3]+=MASIERO14;
			  //			  cout << ">>match 23  " << ast.pack << endl;
			}
		      else
			{
			  cout << ">>match FAILED  " << ast.pack << "--" << line << endl;
			}
		    }
		}
	    }
	}
    myfile.close();
  }
  else cout << "Unable to open file"; 
}
